package com.fj.netty.rpc.message;


import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @author fj
 * @date 2024/1/11 14:29
 */
@Data
public abstract class Message implements Serializable {
    /**
     * 序列号
     */
    private Integer sequenceId;

    public static final byte RPC_REQUEST_MESSAGE = 101;
    public static final byte RPC_RESPONSE_MESSAGE = 102;
    public abstract byte getMessageType();

    private static final Map<Byte,Class<? extends Message>> messageTypeMap = new HashMap<>(10);

    static {
        messageTypeMap.put(RPC_REQUEST_MESSAGE, RpcRequestMessage.class);
        messageTypeMap.put(RPC_RESPONSE_MESSAGE, RpcResponseMessage.class);
    }

    public static Class<? extends Message> getMessageClass(Byte messageType){
        return Message.messageTypeMap.get(messageType);
    }
}
